--POUR CONTROLE


define erp='erp_mli2.';
define outils='outils_mli2.';

--CREATE TABLE se_gen_statut AS (SELECT * FROM &erp.gen_statut WHERE 1=2);




delete from se_gen_statut;

/*statuts article*/
 INSERT INTO se_gen_statut
 (SELECT distinct id statut_cod,
         0 enreg_id,
         'N' enreg_s,
         libelle statut_lib,
         NULL statut_lib2,
         'A' statut_typ
    FROM  UV_PSTATUTS s      );



 UPDATE se_gen_statut tf SET enreg_id=(select enreg_id FROM &erp.gen_statut f WHERE f.statut_cod=tf.statut_cod) ;
 UPDATE se_gen_statut tf SET enreg_id=&outils.enreg_id.NEXTVAL WHERE enreg_id IS NULL;




 CALL uvse_synchroverserp('STATUT_COD','GEN_STATUT','O') ;

 commit;
 
 select * from (
SELECT &outils.stragg(source) source,statut_cod, enreg_id, enreg_s, statut_lib, statut_lib2, statut_typ
FROM (
  SELECT 'uv' source ,g.* FROM se_gen_statut g
  UNION ALL
  SELECT 'se' source ,g.* FROM &erp.gen_statut g where statut_typ='A'
  )
GROUP BY statut_cod, enreg_id, enreg_s, statut_lib, statut_lib2, statut_typ
HAVING Count(1)!=2) r
ORDER BY statut_typ,statut_cod;